package jaux.tank.utils;

import com.nulabinc.zxcvbn.Strength;
import com.nulabinc.zxcvbn.Zxcvbn;

public class PasswordStrengthUtil {

    // 判断密码强度等级：弱、中、强、非常强
    public static final int LEVEL_WEAK = 0;
    public static final int LEVEL_MEDIUM = 1;
    public static final int LEVEL_STRONG = 2;
    public static final int LEVEL_VERY_STRONG = 3;
    
    private PasswordStrengthUtil() {}

    // 判断密码强度
    public static int getPasswordStrength(String password) {
        Zxcvbn zxcvbn = new Zxcvbn();
        Strength strength = zxcvbn.measure(password);
        int score = strength.getScore();
        switch (score) {
            case 0:
            case 1:
                return LEVEL_WEAK;  // 弱的密码
            case 2:
                return LEVEL_MEDIUM;  // 中等强度的密码
            case 3:
                return LEVEL_STRONG;  // 较强的密码
            case 4:
                return LEVEL_VERY_STRONG;  // 非常强的密码
            default:
                return LEVEL_WEAK;  // 密码不符合规则
        }
    }
}
